<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/24
 * Time: 上午12:01
 */

namespace App\Http\Service;


use App\Http\Repository\GoodsRepository;

class GoodsService extends Service
{

    /**
     * @param GoodsRepository $repository
     */
    public function __construct(GoodsRepository $repository)
    {

        parent::__construct($repository);
    }

    public function searchByParams(array $params, $offset, $limit, array $columns = ['*'])
    {

        $where = [];

        foreach ($params as $key => $param) {

            $operator = '=';

            if (in_array($key, ['title', 'short'])) $operator = 'LIKE';

            $where[] = $this->getWhereClause($key, $param, $operator);

        }

        return $this->repository->getGoodsList($where, $offset, $limit, $columns);

    }

    public function getDiscount()
    {
        
    }

    /**
     * @param int $price
     * @param float $discount
     */
    public function getTotal($price, $discount)
    {
        
    }

    public function store()
    {

    }

}